package org.ruizhijie;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.concurrent.ConcurrentLinkedQueue;

import org.ruizhijie.config.BluetoochCardQueue;
import org.ruizhijie.config.SystemConfig;
import org.ruizhijie.config.TopicQueue;
import org.ruizhijie.i.impl.InComPublisherImpl;
import org.ruizhijie.run.InCom;
import org.ruizhijie.run.OutCom;
import org.ruizhijie.run.TcpServer;

public class Main {
	public static Properties properties;
	public static String TOPIC_COMMON = "common";
	
	public static void main(String[] args) {
		loadProperties();
		
		SystemConfig.init(properties);
		
		TopicQueue tq = new TopicQueue();

		for (int i=0;i<SystemConfig.in.size();i++) {
			String inCom = SystemConfig.in.get(i);
			String outCom = SystemConfig.out.get(i);
			
			BluetoochCardQueue.putQues(inCom, new ConcurrentLinkedQueue<String>());
			
			System.err.println(inCom+"--"+outCom);
			
			new Thread(new InCom(new InComPublisherImpl(tq),inCom,outCom),"in"+i).start();
	        new Thread(new OutCom(tq,inCom,outCom),"out"+i).start();
		}
		
//		// UDP读卡器
//		new Thread(new InPortV2(new InPortPublisherImpl(tq), SystemConfig.inPort)).start();
//		new Thread(new OutPort(tq,SystemConfig.inPort+"",SystemConfig.outHost,SystemConfig.outPort)).start();
//		new Thread(new OutPort(tq,SystemConfig.inPort+"",SystemConfig.serverHost,SystemConfig.serverPort)).start();
        
        new TcpServer(tq,TOPIC_COMMON);
	}

	private static void loadProperties() {
		String rootPath = System.getProperty("user.dir").replace("\\", "/");
		
		properties = new Properties();
		try {
			System.err.println(rootPath);
			InputStream inputStream = new FileInputStream(rootPath+"/config.properties");
			properties.load(inputStream);
		} catch (IOException e) {
			e.printStackTrace();
		}
		System.out.println(properties.get("in[0]"));
	}
}
